<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>AP Forest Department R &amp; D Circle</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- Le styles -->
		<link href='http://fonts.googleapis.com/css?family=Monda' rel='stylesheet' type='text/css'>
		<link href="css/style.css" rel="stylesheet">
		<link href="css/aptable-responsive.css" rel="stylesheet">		
		<script src="js/jquery.min.js"></script>
	</head>
	<body style="background:#f5f5f5">
	<?php 
	ini_set('display_errors', '0');
	include("connect.php");
	//echo "<pre>";print_r($_GET);exit;
	if(count($_POST)){
	if(mysql_query("update user set password='".md5($_POST['password'])."',token='' where email_id='".base64_decode($_GET['email'])."'"))
	{
		header("location:ap-admin.php?reset=success");
	}else{
		header("location:reset_password.php?token=".$_GET['token']."&email=".$_GET['email']."&reset=fail");
	}
	}
	?>
		<div style="background:#f5f5f5">
			<div class="wrapper">
				<div class="logo mar_top">
					<img src="images/apfd-Logo.png"/>
				</div>
				<?php if(isset($_GET['token']) && $_GET['token']!=''){
					$query = mysql_query("SELECT user_id from user where email_id='".base64_decode($_GET['email'])."' and token='".$_GET['token']."'");
					$row=mysql_fetch_row($query);
					if($row!=''){ ?>
					
				<div >
					<div class="span4">
						<form class="login" id="reset_form" name="reset_form" method="POST" action="" >
							<h1>Reset Passwprd</h1>
								<div class="inputs ">
									<input class="password span3" id="password" name="password" type="password" placeholder="Password" autofocus required>   
									<input class="password span3" id="cnf_password" name="cnf_password" type="password" placeholder="Confirm Password" required> 
								</div>
								<div id="actions">
									<a onClick="sendFgtEmail();" class="submit" href="javascript:void(0)">Reset</a>
								</div>
								<div class="clear val_red_col"></div>
								<div id="pwdSpanError" class="val_red_col" ></div>
								<div id="cnfpwdSpanError" class="val_red_col" ></div>
						</form>
					</div>
				</div>
				<?}else{echo "Provide link has been expired or invalid";}}else
				{
					echo "Provide link has been expired or invalid";
				}
				?>
			</div>
		</div>
	</body>
	<script type="text/javascript">
	function sendFgtEmail()
	{
	
		var password = $("#password").val().trim();;
		var cnf_password = $("#cnf_password").val().trim();

		if( password == "" )
		{
			$('#pwdSpanError').html('*Please enter password');
			$("#password").focus();
			return false;
		}else{
			$('#pwdSpanError').html('');
		}
		if( cnf_password == "" )
		{
			$('#cnfpwdSpanError').html('*Please enter confirm password');
			$("#cnf_password").focus();
			return false;
		}else{
			$('#cnfpwdSpanError').html('');
		}

		if( password != cnf_password )
		{
			$('.clear').html('*Please enter password and confirm password as same');
			$("#password").focus();
			return false;
		}
		else{
		$("#reset_form").submit();
		}
	}
	</script>
</html>